package cn.ll.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.ll.po.CurrencyRate;
import cn.ll.po.CurrencyRateDAO;

public class CurrencyRateService {
	private CurrencyRateDAO currencyRateDAO = null;
	public void save(CurrencyRate currencyRate){
		currencyRateDAO.save(currencyRate);
	}
	
	public void update(CurrencyRate currencyRate){
		currencyRateDAO.update(currencyRate);
	}
	
	/**
	 * 根据货币的标识查询
	 * @param currency
	 * @return
	 */
	public CurrencyRate findByCurrency(String currency){
		CurrencyRate currencyRate = currencyRateDAO.findById(currency);
		return currencyRate;
	}
	
	public List<CurrencyRate> findAll(){
		List<CurrencyRate> list = currencyRateDAO.findAll();
		return list;
	}
	
	public CurrencyRateDAO getCurrencyRateDAO() {
		return currencyRateDAO;
	}
	public void setCurrencyRateDAO(CurrencyRateDAO currencyRateDAO) {
		this.currencyRateDAO = currencyRateDAO;
	}

	public List<Map> readAllForSelect() {
		List<CurrencyRate> list = currencyRateDAO.findAll();
		
		List<Map> rsLs = new ArrayList<Map>();
		for (CurrencyRate currencyRate : list) {
			Map mp = new HashMap();
			mp.put("key", currencyRate.getCurrency());
			mp.put("value", currencyRate.getCurrencyDesc());
			rsLs.add(mp);
		}
		
		return rsLs;
	}
}
